* Program to compute ASL of difference of means using naive moving block bootstrap
* and HAC-corrected standard errors

* This program: 1966-1997 vs. 1998-2006 samples, std. dev.-based NSRs


calendar 1947 1 4
allocate 2020:04+5000


open data table1_reg_test_data.rat
data(format=rats) / gb_revgapvr_f32 gb_revgapvr_f09



set gb_revgapvr 1966:01 1997:04 = gb_revgapvr_f32
set gb_revgapvr 1998:01 2006:04 = gb_revgapvr_f09


seed 43892



* Set bootstrap and related parameters

compute ndraws=5000
compute nblocks=4
compute haclags=4
set t_ovn_stddev = %NA


set dum98q1 = 0.0
set dum98q1 1998:01 2006:04 = 1.0

linreg(robusterrors,lags=haclags,lwindow=neweywest) gb_revgapvr
# constant dum98q1


statistics(noprint) gb_revgapvr 1966:01 1997:04
compute mean1=%mean
statistics(noprint) gb_revgapvr 1998:01 2006:04
compute mean2=%mean
statistics(noprint) gb_revgapvr 1966:01 2006:04
compute meanfull=%mean

disp "Difference in means = " mean2-mean1


set zzz 1966:01 1997:04 = gb_revgapvr-mean1+meanfull
set yyy 1998:01 2006:04 = gb_revgapvr-mean2+meanfull


do iter=1,ndraws

  set b_zzz = %NA
  set b_yyy = %NA

  boot(replace,block=nblocks,method=overlap) b_entry1 1966:01 1997:04
  set b_zzz = zzz(b_entry1)

  boot(replace,block=nblocks,method=overlap) b_entry2 1998:01 2006:04
  set b_yyy = yyy(b_entry2)

  linreg(robusterrors,lags=haclags,lwindow=neweywest,noprint) b_zzz
  # constant
  compute mean_bzzz=%beta(1)
  compute se_bzzz=%stderrs(1)

  linreg(robusterrors,lags=haclags,lwindow=neweywest,noprint) b_yyy
  # constant
  compute mean_byyy=%beta(1)
  compute se_byyy=%stderrs(1)

  set t_ovn_stddev iter iter = (mean_byyy-mean_bzzz)/sqrt((se_bzzz**2.0)+(se_byyy**2.0))


end do iter



* Tabulate bootstrapped t-statistics

statistics(fract) t_ovn_stddev


